﻿using EasyDDD.AdminModule.Application.CommandsSysMenu;

namespace EasyDDD.AdminModule.Application.CommandsSysAdminRole
{
    public record SysAdminRoleSetMenuCommand : ICommand<string>
    {
        public Guid Id { get; set; }
        public virtual Guid RowVersion { get; set; } = default!;
        public Guid[] SysMenuIds { get; set; } = default!;
    }


    public class SysAdminRoleSetMenuCommandHandler(
        //IMapper mapper,
        Repository.SysAdminRoleRepository repository,
        ILogger<SysMenuUpdateCommandHandler> logger)
        : ICommandHandler<SysAdminRoleSetMenuCommand, string>
    {
        public async Task<string> Handle(SysAdminRoleSetMenuCommand request, CancellationToken cancellationToken)
        {
            logger.LogDebug("命令 SysAdminRoleSetMenuListCommandHandler");
            var entity = await repository.GetAsync(request.Id, request.RowVersion);
            entity.SetSysMenuRuleList(request.SysMenuIds);
            return "菜单权限设置成功！";
        }
    }

}
